//
//  YDChoosePayTypeFooterView.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2017/12/19.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDChoosePayTypeFooterView.h"
#import <WebKit/WebKit.h>

@interface YDChoosePayTypeFooterView()<UIWebViewDelegate>
//温馨提示
@property (nonatomic , weak) UILabel *postLabel;
//内容
@property (nonatomic , weak) UILabel *detailLabel;
//客服电话
@property (nonatomic, strong)UILabel *customePhoneLbl;
//温馨提示内容webview
@property (nonatomic, strong)UIWebView *tipsWebview;


@end

@implementation YDChoosePayTypeFooterView


- (void)setPayType:(SYPayType)payType
{
    _payType = payType;
    
    NSString *html = nil;
    switch (payType) {
        case SYPayType_card:
            html = @"WarmTips";
            break;
        case SYPayType_jd:
            html = @"WarmTips_JD";
            break;
        case SYPayType_qq:
            html = @"WarmTips_QQ";
            break;
        default:
            break;
    }
    [self.tipsWebview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:html ofType:@".html" ]]]];
}

+ (instancetype)footerViewWithTableView:(UITableView *)tableView
{
    
    static NSString *rechargeTableFooterView = @"YDChoosePayTypeFooterView";
    YDChoosePayTypeFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:rechargeTableFooterView];
    if (footerView == nil) {
        footerView = [[YDChoosePayTypeFooterView alloc] initWithReuseIdentifier:rechargeTableFooterView];
    }
    return footerView;
}


-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self tipsWebview];
        
    }
    return self;
}

- (void)callPhone
{
    NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",CustomerPhone];
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self callPhone];
        });
        return NO;
    }else
    {
        return YES;
    }
    
}
-(UIWebView *)tipsWebview
{
    if (_tipsWebview == nil) {
        _tipsWebview = [UIWebView new];
        _tipsWebview.scrollView.scrollEnabled = NO;
        _tipsWebview.delegate = self;
        _tipsWebview.userInteractionEnabled = YES;
        [self.contentView addSubview:_tipsWebview];
        _tipsWebview.backgroundColor = [UIColor colorWithHexString:mainGray];
        [_tipsWebview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            
            if (isPhoneX) {
                make.top.equalTo(self.contentView).offset(rateX812(10));
            }else{
                make.top.equalTo(self.contentView).offset(rate750(10));
            }
            make.height.equalTo(@200);
        }];
        
        
        
        
    }
    return _tipsWebview;
}

@end
